import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    redirect: '/dashboard'
  },
  {
    path:'/',
    component: () => import('components/common/Home.vue'),
    meta: {title: '自述文件' },
    children: [
      {
        path:'/dashboard',
        component: () => import('views/Dashboard.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path:'/table',
        component: () => import('views/BaseTable.vue'),
        meta: {
          title: '表格'
        }
      },
      {
        path: '/tabs',
        component: ()=> import('views/Tabs.vue'),
        meta: {
          title: 'tabs标签'
        }
      },
      {
        path: '/form',
        component: ()=> import('views/BaseForm.vue'),
        meta: {
          title: '基本表单'
        }
      },
      {
        path: '/editor',
        component: ()=> import('views/VueEditor.vue'),
        meta: {
          title: '富文本编辑器'
        }
      },
      {
        path: '/markdown',
        component: ()=> import('views/MarkDown.vue'),
        meta: {
          title: 'markdown编辑器'
        }
      },
      {
        path: '/upload',
        component: ()=> import('views/Upload.vue'),
        meta: {
          title: '文件上传'
        }
      },
      {
        path: '/icon',
        component: ()=> import('views/Icon.vue'),
        meta: {
          title: '自定义图标'
        }
      },
      {
        path: '/404',
        component: () => import('views/404.vue'),
        meta: { title: '404' }
      },
      {
          path: '/403',
          component: () => import('views/403.vue'),
          meta: { title: '403' }
      },
      {
        // 拖拽列表组件
        path: '/drag',
        component: () => import('views/DragList.vue'),
        meta: { title: '拖拽列表' }
      },
      {
        // vue-schart组件
        path: '/charts',
        component: () => import('views/BaseEcharts.vue'),
        meta: { title: 'schart图表' }
    },
    ]
  },
  {
    path: '/login',
    component: () => import('views/Login.vue'),
    meta: {
      title: '登录'
    }
  }
]

const router = new VueRouter({
  routes,
  mode: 'history'
})

// 使用路由守卫对路由进行权限跳转
router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  const role = localStorage.getItem('ms_username');
  if (!role && to.path != '/login') {
    next('/login');
  }
  else {
    next();
  }
})

export default router
